Total Complexity | 2 |
Total Lines | 23 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import { Inject } from '@nestjs/common'; |
||
7 | |||
8 | @QueryHandler(GetCustomersQuery) |
||
9 | export class GetCustomersQueryHandler { |
||
10 | constructor( |
||
11 | @Inject('ICustomerRepository') |
||
12 | private readonly customerRepository: ICustomerRepository |
||
13 | ) {} |
||
14 | |||
15 | public async execute( |
||
16 | query: GetCustomersQuery |
||
17 | ): Promise<Pagination<CustomerView>> { |
||
18 | const customerViews: CustomerView[] = []; |
||
19 | const [customers, total] = await this.customerRepository.findCustomers( |
||
20 | query.page |
||
21 | ); |
||
22 | |||
23 | for (const customer of customers) { |
||
24 | customerViews.push( |
||
25 | new CustomerView(customer.getId(), customer.getName()) |
||
26 | ); |
||
27 | } |
||
28 | |||
29 | return new Pagination<CustomerView>(customerViews, total); |
||
30 | } |
||
32 |